package com.yrmao.mviewpagergridview;

import android.os.Bundle;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;

import com.yrmao.mviewpagergridview.adapter.MViewPagerAdapter;
import com.yrmao.mviewpagergridview.modles.GridviewContentInfo;

import java.util.ArrayList;
import java.util.List;

public class MainActivity extends AppCompatActivity {
    private ViewPager viewPager1, viewPager2;
    private int[] image = {R.mipmap.ic_launcher, R.mipmap.ic_launcher, R.mipmap.ic_launcher, R.mipmap.ic_launcher, R.mipmap.ic_launcher, R.mipmap.ic_launcher, R.mipmap.ic_launcher, R.mipmap.ic_launcher, R.mipmap.ic_launcher, R.mipmap.ic_launcher, R.mipmap.ic_launcher, R.mipmap.ic_launcher, R.mipmap.ic_launcher, R.mipmap.ic_launcher, R.mipmap.ic_launcher,};
    private String[] content = {"红包助手", "地图", "公交线路", "待定1", "待定2", "待定3", "待定1", "待定2", "待定3", "待定1", "待定2", "待定3", "待定1", "待定2", "待定3"};
    private String[] imageUrl = {"", "", "", "", "", "", "", "", "", "", "", "", "", "", "",};
    private int pagesize = 4;//每页显示个数
    private List<GridviewContentInfo> listContent;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        initData();
        initview();
    }

    private void initview() {

        viewPager1 = (ViewPager) findViewById(R.id.viewpager1);
        viewPager2 = (ViewPager) findViewById(R.id.viewpager2);
        viewPager1.setAdapter(new MViewPagerAdapter(listContent, pagesize, this));
        viewPager2.setAdapter(new MViewPagerAdapter(listContent, 8, this));
    }

    private void initData() {
        listContent = new ArrayList<>();
        GridviewContentInfo info;
        for (int i = 0; i < image.length; i++) {
            info = new GridviewContentInfo();
            info.setMainContentInfo(image[i], imageUrl[i], content[i]);
            listContent.add(info);
        }

    }
}
